home *** CD-ROM | disk | FTP | other *** search
- Path: news.iadfw.net!usenet
- From: Mark Nelson <markn@airmail.net>
- Newsgroups: comp.lang.c++
- Subject: Re: Vector of abstract classes using STL
- Date: Mon, 22 Jan 1996 16:57:15 -0600
- Organization: customer of Internet America
- Message-ID: <3104164B.68A0@airmail.net>
- References: <3103699A.79F8@ce.kth.se>
- NNTP-Posting-Host: dal06-21.ppp.iadfw.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b3 (Win95; I)
-
- Anders Olsson wrote:
- >
- > I have an abstract class Shape, that has pure virtual functions.
- > From this class I derive rectangle and circle classes.
- > I want to use a vector for storing the shapes.
- >
- > I've tried using a vector<Shape>, but I get compiler errors because
- > the Shape class cannot be instantiated. This must be the wrong way of
- > doing it I understand.
- >
- > I think I have to use a vector<Shape*> but does the vector delete
- > the shape elements when the program finishes?
- >
-
- No, it doesn't. The vector destructor will call the explicity
- destructor for Shape *, which will probably do nothing at all. So to
- get good cleanup, you might want to create a wrapper class that performs
- an auto_ptr type function.
-
- Mark Nelson
- http://web2.airmail.net/markn
-